<?php
/**
 * The template for displaying archive pages
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header("news"); ?>

<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/news.css" />
<script src="<?php echo get_template_directory_uri(); ?>/js/news.js"></script>

<div class="wrapi body body2">

	<?php
		$curtag = urldecode(get_query_var( 'tag' ));
	?>

	<ul class="nav">
		<li class="<?php if ($curtag == '') echo 'all' ?>"><a href="/category/news">全部</a></li>
		<li class="<?php if ($curtag == '报道') echo 'all' ?>"><a href="/category/news?tag=报道">报道</a></li>
		<li class="<?php if ($curtag == '培训') echo 'all' ?>"><a href="/category/news?tag=培训">培训</a></li>
		<li class="<?php if ($curtag == '团队建设') echo 'all' ?>"><a href="/category/news?tag=团队建设">团队建设</a></li>
	</ul>

	
	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
		
		<?php
		if ( have_posts() ) : ?>
		<div class="content">
			<ul class="list">    
				<?php            
				/* Start the Loop */
				while ( have_posts() ) : the_post();
        	                     
					/*           
					 * Include the Post-Format-specific template for the content.
					 * If you want to override this in a child theme, then include a file
					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
					 */          
					// get_template_part( 'template-parts/post/content', get_post_format() );
        	                     			
					/** 新闻中所有图片 */
					$images = get_content_image( $post->post_content );
					/** 新闻中第一张图片 */
					$firstimage = $images[0];
					/** 新闻内容中去掉图片 */
					$content = preg_replace('/<img[^>]+>/i','', $post->post_content);
					/** 删除 <br /> */
					$content = preg_replace('/<br \\/>/i','', $content);
					/** 新闻内容中删除空行 p */
					$content = preg_replace('/<p[^>]*>\s*<\\/p[^>]*>/', '', $content); 

					$start = 1;
					
					$titles = split("###", $post->post_title);
					$title_chn = $titles[0];
					$title_eng = $titles[0];
					if (count($titles) > 1) {
						$title_eng = $titles[1];
					}

				?>
					<li data-type="gdbs">
						<span class="date"><?php twentyseventeen_posted_on() ?></span>
						<div class="detail">
							<h3 data-chn="<?php echo $title_chn; ?>" data-eng="<?php echo $title_eng; ?>"></h3>
							<div class="content2"><?php echo $content; ?></div>
							<div class="more">更多</div>
						</div>
						<div class="img">
							<img src="<?php echo $firstimage; ?>">
							<ul class="more-img" style="display: none;">
							<?php 
								while ($start < count($images)) {
							?>
									<li class="loading"><img src="<?php echo $images[$start]; ?>" onload="imgOnload(this)"></li>
							<?php
									$start = $start + 1;
								}
							?>
							</ul>
						</div>
					</li>
			<?php  
				endwhile;
			?>

			</ul>
		</div>
		<div class="page">
		<?php

			the_posts_pagination( array(
				'prev_text' => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
				'next_text' => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
				'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
			) );

		endif; ?>
		</div>

		</main><!-- #main -->
	</div><!-- #primary -->
	<!--?php get_sidebar(); ?-->
</div><!-- .wrap -->

<?php get_footer();
